package cn.wit.front.service.impl;

import cn.wit.front.condition.SearchCompanyCondition;
import cn.wit.front.mapper.CompanyMapper;
import cn.wit.front.mapper.RecruitInfoMapper;
import cn.wit.front.service.CompanyService;
import cn.wit.front.service.RecruitInfoService;
import cn.wit.utils.pojo.Company;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private RecruitInfoMapper recruitInfoMapper;

    @Autowired
    private RecruitInfoService recruitInfoService;


    @Override
    public Result selectAllCompany() {
        List<Company> companies = companyMapper.selectList(null);
        if(!CollectionUtils.isEmpty(companies)){
            return Result.ok(companies);
        }
        return Result.ok(new ArrayList<>());
    }

    @Override
    public Result searchPage(IPage<Company> page, SearchCompanyCondition condition) {
        QueryWrapper<Company> wrapper = new QueryWrapper<>();
        if(condition != null) {
            if(condition.getName() != null && condition.getName() != "") {
                wrapper.like("name", condition.getName());
            }
            if(condition.getNature() != null && condition.getNature() != "") {
                wrapper.like("nature", condition.getNature());
            }
            if(condition.getIsAppear() != null && condition.getIsAppear() != "") {
                wrapper.like("isAppear", condition.getIsAppear());
            }
        }
        IPage<Company> companyIPage = companyMapper.selectPage(page, wrapper);
        return Result.ok(companyIPage);
    }
}
